/**
 * 
 */
package midterm;

/**
 * @author Lucas
 *
 */
public class BinaryOps {

	public void and(int x, int y, boolean print){
		if(print) System.out.println(printHexInfo(x));
		if(print)System.out.println(printHexInfo(y));
		int combin = x & y;
		if(print)System.out.println(x + " and'ed with " + y + " result: " + printHexInfo(combin) );
	}
	
	private String printHexInfo(int x) {
		String hexStr = Integer.toHexString(x);
		String binaryStr = Integer.toBinaryString(x);
		String out = "Decimal value is " + x + 
				"   Hex value is " + hexStr + "   Binary value is " + binaryStr ;
		return out;
	}

	public void or(int x, int y, boolean print){
		if(print) System.out.println(printHexInfo(x));
		if(print)System.out.println(printHexInfo(y));
		int combin = x | y;
		if(print)System.out.println(x + " or'ed with " + y + " result: " + printHexInfo(combin) );
	}
	
	public static void main(String[] args) {
		BinaryOps bo = new BinaryOps();
		bo.and(0xfff, 0xbad, true);
		bo.and(0xbad, 0xa6f, true);
		bo.or(0xfff, 0xabc, true);
		bo.or(0xabcde, 0x1234, true);
	}

}
